package com.caseProject.puremvc.mediator
{
	import com.caseProject.puremvc.mediator.events.MenuEditOptionsEvent;
	import com.caseProject.puremvc.mediator.gui.Element;
	import com.caseProject.puremvc.mediator.gui.Transition;
	import com.caseProject.puremvc.mediator.view.MenuEditOptionsView;
	import com.caseProject.puremvc.model.Diagram;
	import com.caseProject.puremvc.notifications.NotificationNames;
	
	import flash.events.Event;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class MenuEditOptionsMediator extends Mediator implements IMediator
	{
		public static const NAME:String = "MenuEditOptionsMediator";
				
		public function MenuEditOptionsMediator(viewComponent:MenuEditOptionsView)
		{
			super(NAME, viewComponent);
			this.menuEditOptionsView.addEventListener(MenuEditOptionsEvent.STATE, onNewState);
			this.menuEditOptionsView.addEventListener(MenuEditOptionsEvent.ACTIVITY, onNewActivity);
			this.menuEditOptionsView.addEventListener(MenuEditOptionsEvent.RENAME_DIAGRAM_SUCESS, onRenameDiagram);
		}
		
		protected function onRenameDiagram(event:Event):void
		{
			this.sendNotification(NotificationNames.MENU_EDIT_RENAME_DIAGRAM_SUCCESS);
		}
		
		public function get menuEditOptionsView():MenuEditOptionsView
		{
			return viewComponent as MenuEditOptionsView;
		}
		
		protected function onNewActivity(event:MenuEditOptionsEvent):void
		{
			this.sendNotification(NotificationNames.NEW_DIAGRAM_ACTIVITY);
		}
		
		protected function onNewState(event:MenuEditOptionsEvent):void
		{
			this.sendNotification(NotificationNames.NEW_DIAGRAM_STATE);
		}		
		
		override public function listNotificationInterests():Array
		{
			return [
					NotificationNames.PROJECT_MENU_NOVO_DIAGRAMA,
					NotificationNames.MENU_EDIT_STATE,
					NotificationNames.MENU_EDIT_TRANSITION,
					NotificationNames.GRAPHIC_EDIT_STATE,
					NotificationNames.MENU_EDIT_RENAME_DIAGRAM
					];
		}
		
		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case NotificationNames.PROJECT_MENU_NOVO_DIAGRAMA:
					this.menuEditOptionsView.changeBehaviorNewDiagram();
					break;
				
				case NotificationNames.MENU_EDIT_STATE:
					var elem:Element = notification.getBody() as Element;
					this.menuEditOptionsView.changeBehaviorEditState(elem);
					break;
				
				case NotificationNames.MENU_EDIT_RENAME_DIAGRAM:
					var diagramVO:Diagram = notification.getBody() as Diagram;
					this.menuEditOptionsView.changeBehaviorRenameDiagram(diagramVO);
					break;
				
				case NotificationNames.MENU_EDIT_TRANSITION:
					var trans:Transition = notification.getBody() as Transition;
					this.menuEditOptionsView.changeBehaviorEditTransition(trans);
					break;
				
				case NotificationNames.GRAPHIC_EDIT_STATE:
					this.menuEditOptionsView.removeMenuEditOption();
					break;
			}
		}
	}
}